<?php
namespace app\app\model;
use think\Model;
class Loginlog extends Model
{
    public function saveLoginLog($user_info)
    {
        $hasLog = db('loginlog')->where('user_id',$user_info['id'])->find();
        $loginlog = new Loginlog;
        $list = [
            'user_id' => $user_info['id'],
            'warehouse_id' => $user_info['warehouse_id'],
        ];
        if ($hasLog == false){
            $logins = array();
            array_push($logins, time());
            $logins = json_encode($logins);
            $list['logins'] = $logins;
            $save_loginlog = $loginlog->save($list);
        }else {
            $logins = json_decode($hasLog['logins']);
            array_push($logins, time());
            $logins = json_encode($logins);
            $list['logins'] = $logins;
            $save_loginlog = $loginlog->save($list,['user_id' => $user_info['id']]);
        }
        return $save_loginlog;
    }
}